﻿using System;

namespace demo {

  public class TransitionDemo {
    static void Main(string[] args) {
      Console.WriteLine("\n# 状態:");
      foreach ( book.State st in book.State.list() ) {
        Console.WriteLine("# {0}:{1}", (int)st.code(), st.name());
      }
      Console.WriteLine("\n# 事象:");
      foreach ( book.Event ev in book.Event.list() ) {
        Console.WriteLine("# {0}:{1}", (int)ev.code(), ev.name());
      }
      Console.WriteLine();

      book.Context context = new book.ConsoleContext();
      book.StateMachine machine = new book.StateMachine(context);
      // 発注済(=入荷待ち)から始めるよ!
      machine.setState(book.State.Code.Ordered);

#if DEMO
      machine.handle(new book.E_Comein());        // 入荷
      machine.handle(new book.E_Lend());          // 貸出
      machine.handle(new book.E_Return());        // 返却
      machine.handle(new book.E_Return());        // 返却(無理!)
      machine.handle(new book.E_Repair());        // 補修
      machine.handle(new book.E_Lend());          // 貸出(無理!)
      machine.handle(new book.E_Repaired());      // 補修完了
      machine.handle(new book.E_Reserve());       // 予約
      machine.handle(new book.E_Cancelreserve()); // 予約取消
      machine.handle(new book.E_Dispose());       // 廃棄
#else
      string line;
      while ( (line = Console.ReadLine()) != null ) {
        if ( line.Length <= 0 ) continue;
        switch ( line[0] ) {
        case '0': machine.handle(new book.E_Comein());        break;
        case '1': machine.handle(new book.E_Repair());        break;
        case '2': machine.handle(new book.E_Lend());          break;
        case '3': machine.handle(new book.E_Expire());        break;
        case '4': machine.handle(new book.E_Extend());        break;
        case '5': machine.handle(new book.E_Return());        break;
        case '6': machine.handle(new book.E_Reserve());       break;
        case '7': machine.handle(new book.E_Cancelreserve()); break;
        case '8': machine.handle(new book.E_Repaired());      break;
        case '9': machine.handle(new book.E_Dispose());       break;
        default: /* do nothing */ break;
        }
      }
#endif
}
  }

}
